
<!-- eslint-disable vue/no-mutating-props -->
<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div class="box"  v-if="isdeleteShow">
      <span @click="$emit('update-history',[])">全部删除</span>&nbsp;&nbsp;
      <span @click="isdeleteShow=false">完成</span>
      </div>
       <van-icon name="delete" @click="isdeleteShow=true" v-else />
    </van-cell>
    <van-cell :title="item" v-for="(item, i) in history" :key="i" @click="changeEdit(item,i)">
      <van-icon name="close" v-show="isdeleteShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: { // 单向传递，引用类型不能直接赋值，只能更改属性
    history: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isdeleteShow: false // 控制是否删除
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    changeEdit (item, i) {
      if (this.isdeleteShow) { // 编辑状态 ，直接删除
        // eslint-disable-next-line vue/no-mutating-props
        this.history.splice(i, 1)
      } else { // 非删除状态，直接跳转
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang="less">
.van-icon-close{
  color: red;
}</style>
